package volatileTest;

/**
 * todo
 *
 * @author: luolidong
 * @create: 2021-07-09 22:42
 * @version: 1.0
 */
class VolatileBarrierExample {
    int a;
    volatile int v1 = 1;
    volatile int v2 = 2;

    void readAndWrite() {
        int i = v1; // 第一个volatile读
        int j = v2; // 第二个volatile读
        a = i + j; // 普通写
        v1 = i + 1; // 第一个volatile写
        v2 = j * 2; // 第二个 volatile写
    }
    /*
    * aload_0
 1 getfield #2 <volatileTest/VolatileBarrierExample.v1>
 4 istore_1
 5 aload_0
 6 getfield #3 <volatileTest/VolatileBarrierExample.v2>
 9 istore_2
10 aload_0
11 iload_1
12 iload_2
13 iadd
14 putfield #4 <volatileTest/VolatileBarrierExample.a>
17 aload_0
18 iload_1
19 iconst_1
20 iadd
21 putfield #2 <volatileTest/VolatileBarrierExample.v1>
24 aload_0
25 iload_2
26 iconst_2
27 imul
28 putfield #3 <volatileTest/VolatileBarrierExample.v2>
31 return

    */
}
